<jsp:useBean id="cadForBean" scope="request"
	class="edu.up.beans.FornecedorBean" />
<script type="text/javascript">
			function FormataCnpj(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
					if (tam == 10)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
					if (tam == 15)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
				}
			}
			
			function SomenteNumero(e){
			    var tecla=(window.event)?event.keyCode:e.which;   
			    if((tecla>47 && tecla<58)) return true;
			    else{
			    	if (tecla==8 || tecla==0) return true;
				else  return false;
			    }
			}
		</script>

<input type="text" name="cnpj" maxlength="18" value='<jsp:getProperty property='cnpj' name='cadForBean'/>'
	onkeypress="FormataCnpj(this,event);return SomenteNumero(event)"/>

